$(function(){
	//固定的导航栏的消失 显示
	$(window).scroll(function(){
		var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
		if(scrollTop>200){
			$(".Search").css({"display":"block"});
			$(".Search").fadeIn("slow");
		}else{
			$(".Search").css({"display":"none"});
			$(".Search").fadeOut("slow");	
		}
	});
    //鼠标滑过Title 的 a 变色
    $(".Title ul li a").hover(function(){
    	$(".Title ul li a").css({"color":"#4F4F4F"});
	 	$(this).css({"color":"#8E0C3A","text-decoration":"none"});
    });
    //轮播图  及 左右按钮
    var index=1;
    var bool=true;
    var time=setInterval(function(){
    	if(bool){
    		
    		animate($(".ScrollImg")[0],{left:-960*index},{callback:function(){
    			if(index==4){
    				$(".ScrollImg")[0].style.left=0;
    				index=0;
    			}
    			index++;
    		}});
    	}
    	
    },5000);
    $(".Toleft").click(function(){
    	console.log("------"+index);
    	if(index==1){
    		$(".ScrollImg")[0].style.left= -2880+"px";
    		index=4;
    	}else {
			index -= 2;
			animate($(".ScrollImg")[0],{left:-960*index},{callback:function(){
    		    if(index==4){
    				$(".ScrollImg")[0].style.left=0;
    				index=0;
    			}
    			index++;
    		}});
		}
    });
    $(".Toright").click(function(){
    	console.log("------"+index);
    	animate($(".ScrollImg")[0],{left:-960*index},{callback:function(){
    		if(index==4){
    			$(".ScrollImg")[0].style.left=0;
    			index=0;
    		}
    		index++;
    	}});
    });
    $(".Scroll-img").mousemove(function(){
    	 $(".Toright").css({"display":"block"});
    	 $(".Toleft").css({"display":"block"});
    	 bool=false;
    });
    $(".Scroll-img").mouseout(function(){
    	console.log("---------");
    	$(".Toright").css({"display":"none"});
    	$(".Toleft").css({"display":"none"});
    	bool=true; 
    });
    //2及导航的出现
    $(".newthing").mouseenter(function(){
    	$(".MzineChildren").css({"display":"block"});
    	$(".MzineChildren").mouseenter(function(){
    		$(".MzineChildren").css({"display":"block"});
    	});
    	$(".MzineChildren").mouseleave(function(){
    		$(".MzineChildren").css({"display":"none"});
    	});
    	
    });
    $(".newthing").mouseleave(function(){
    	console.log("==========");
    	$(".MzineChildren").css({"display":"none"});
    });
    //正被选购
    var count=1;
    var times=setInterval(function(){
    	animate($(".Banner")[0],{left:-170*count},{callback:function(){
    		console.log("1111"+count);
    		if(count==8){
    				$(".Banner")[0].style.left=0;
    				count=0;
    			}
    			count++;

    	}});
    },2000);
       $(".Tolefts").click(function(){
    	console.log("------"+count);
    	clearInterval(times);
        animate($(".Banner")[0],{left:-170*count},{callback:function(){
        	if(count==8){
                count=0;
        		$(".Banner")[0].style.left=0;
        	}
			count++;
    	}});
    });
    $(".Torights").click(function(){
    	console.log("------"+count);
    	clearInterval(times);
        animate($(".Banner")[0],{left:-170*(count-1)},{callback:function(){
        	if(count==0){
        		count=8;
        		$(".Banner")[0].style.left= -1200+"px";
        	}
			count--;
    	}});
    });
    //用户登录验证连接数据库 服务器
	$(".btn_login").click(function(){
		var name =$("#username").val();
		var passwords=$("#password").val();
		$.ajax({
       		type: "GET",
        	url: 'http://10.9.166.8/login.php?account='+name+'&password='+passwords,
        	success: function (data) {
           		if (data != "") {
               /* $("#pager").pager({ pagenumber: pagenumber, pagecount: data.split("$$")[1], buttonClickCallback: PageClick });
                $("#anhtml").html(data.split("$$")[0]);
*/          	console.log("---"+data);
                console.log("===========");
           		}
        	}
    	});
	});
	var flag=false;
	(jQuery.fn.Validate=function(yonghu,shuchu){
   		var pattern = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;
		var email=$(yonghu).val();
		$.fn.isMobilePhones(email);
		if(email==''){
				$(shuchu).css({"display":"block"});
				$(shuchu).html("用户名不能为空");
				$(shuchu).css({"color":"#F00"});
		}else if(flag||email.length==11){
			if(flag){
				$(shuchu).css({"display":"none"});
			}else if(email.length==11){
				$(shuchu).css({"display":"block"});
				$(shuchu).html("手机格式错误");
				$(shuchu).css({"color":"#F00"});
			}
			
		}else{
			if(!pattern.test(email)){
				$(shuchu).css({"display":"block"});
				$(shuchu).html("邮箱格式错误");
				$(shuchu).css({"color":"#F00"});
			}
		}
  	});
   (jQuery.fn.isMobilePhones=function(value){
   		if(value.search(/^(\+\d{2,3})?\d{11}$/) == -1){
        	return flag;
    	}else{
        	return flag=true;
    	}
   });
   $("#username").blur(function(){
   	$.fn.Validate("#username",".input_x p");
   });
	$("#password").blur(function(){
   	$.fn.Validate("#username",".input_xx p");
   });

    
  
});
		
		
	

